package  
{
	import bulletbehavior.RotateBehavior;
	import bulletbehavior.TypeCyclingBehavior;
	import bulletbehavior.WaveBehavior;
	import bulletbehavior.WaveBehaviorAngular;
	import org.flixel.FlxG;
	import turretbehavior.SpeedModulationBehavior;
	import turretbehavior.SpinningTurretBehavior;
	import turretbehavior.TypeCyclingTurretBehavior;
	/**
	 * ...
	 * @author morgan
	 */
	public class Stage6State extends GameState
	{
		
		public function Stage6State() 
		{
			super();
			levelName = "2-3";
			levelIndex = 5;
			chefName = "sir bisque";
			img_terrain = img_terrain_2;	
		}
		
		override public function setupBoss():void 
		{
			boss = new Boss(FlxG.width / 2 - 70, 10, 1);
			
			var straight:BulletPattern = new BulletPattern();
			
			var boxL:BulletPattern = new BulletPattern();
			boxL.addBehavior(new RotateBehavior(90), 1.0);
			boxL.addBehavior(new RotateBehavior(90), 1.5);
			boxL.addBehavior(new RotateBehavior(90), 2.0);
			boxL.addBehavior(new RotateBehavior(90), 2.58);
			
			var boxR:BulletPattern = new BulletPattern();
			boxR.addBehavior(new RotateBehavior(-90), 1);
			boxR.addBehavior(new RotateBehavior(-90), 1.5);
			boxR.addBehavior(new RotateBehavior(-90), 2.0);
			boxR.addBehavior(new RotateBehavior( -90), 2.58);	
			
			var wavey:BulletPattern = new BulletPattern();
			wavey.addBehavior(new WaveBehaviorAngular(2, 140, 0));
			
			var p1f:BossPattern = new BossPattern();
			for (var i:int = 0; i < 7; i++)
			{
				var tt:Turret;
				if(i < 3) { 
					tt = new Turret((i - 3) * 15, -20, boxL, i % 3, 90 + (i - 3) * -4, 130, 1.5);
				}
				else if (i == 3)
				{
					tt = new Turret((i - 3) * 15, -20, straight, i % 3, 90 + (i - 3) * -4, 130, 1.5);
				}
				else
				{
					tt = new Turret((i - 3) * 15, -20, boxR, i % 3, 90 + (i - 3) * -4, 130, 1.5);
				}
				tt.addBehavior(new TypeCyclingTurretBehavior(1.5, [i / 3 % 3, (i / 3 + 1) % 3, (i / 3 + 2) % 3]));
				p1f.addTurretTime(0, Infinity, tt);
			}
			
			var p2f:BossPattern = new BossPattern();
			var t1t:Turret = new Turret( -100, -80, wavey, 0, 0, 50, 0.2, true);
			t1t.addBehavior(new TypeCyclingTurretBehavior(0.6, [0, 1, 2]));
			t1t.addBehavior(new SpinningTurretBehavior(4, 10, true));
			var t2t:Turret = new Turret( 100, -5, wavey, 0, 180, 50, 0.2, true);
			t2t.addBehavior(new TypeCyclingTurretBehavior(0.6, [1, 0, 2]));
			t2t.addBehavior(new SpinningTurretBehavior(-4, 10, true));
			var t3t:Turret = new Turret( -100, 25, wavey, 0, 0, 50, 0.2, true);
			t3t.addBehavior(new TypeCyclingTurretBehavior(0.6, [0, 2, 1]));
			t3t.addBehavior(new SpinningTurretBehavior(4, 10, true));
			var t4t:Turret = new Turret( 100, 100, wavey, 0, 180, 50, 0.2, true);
			t4t.addBehavior(new TypeCyclingTurretBehavior(0.6, [2, 0, 1]));
			t4t.addBehavior(new SpinningTurretBehavior(-4, 10, true));
			p2f.addTurretTime(0, Infinity, t1t);
			p2f.addTurretTime(1, Infinity, t2t);
			p2f.addTurretTime(2, Infinity, t3t);
			p2f.addTurretTime(3, Infinity, t4t);
			
			
			var p3f:BossPattern = new BossPattern();
			for (i = 0; i < 14; i++)
			{
				var turn:BulletPattern = new BulletPattern();
				turn.addBehavior(new RotateBehavior( (i % 2) * 180 - 90), 0.3 + i / 6);
				tt = new Turret( (i % 2) * -16 + 8, i*2, turn, i % 3, 90, 90, 1.0);
				p3f.addTurretTime(0, Infinity, tt);
			}
			
			var p4f:BossPattern = new BossPattern();
			var lastTime:Number = 0;
			for (i = 0; i < 5; i++)
			{
				tt = new Turret(0, 0, straight, 0, 45, 70, 0.1 - i / 50);
				tt.addBehavior(new TypeCyclingTurretBehavior(0.4, [0, 1, 2]));
				tt.addBehavior(new SpinningTurretBehavior(45 + i * 50, 90, true));
				
				p4f.addTurretTime(lastTime, lastTime + 180 / (45 + i * 50), tt);
				lastTime = lastTime + 180 / (45 + i * 50);
			}
		
			boss.addState(new BossState(1000, p2f));
			boss.addState(new BossState(700, p1f));
			boss.addState(new BossState(1000, p3f));
			boss.addState(new BossState(1300, p4f));	
		}
		
	}

}